package com.exam.action;


import java.sql.SQLException;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;

import com.exam.dao.GradeDao;
import com.exam.dao.QuestionDao;
import com.exam.dao.StudentDao;
import com.exam.service.PageService;
import com.exam.util.Tools;


public class GradeAction implements RequestAware{
	
	private GradeDao gdao;
	private String pageNow="1";
	private String sid=""; 
	private int gid;  
	private int pid=-1;
	
	private String pname;
	
	/**
	 * 
	 * Description:list
	 * @author: 刘楠
	 * @date: 2017年4月19日
	 * @return
	 */
	public String list(){
		gdao = new GradeDao();
		try {
			PageService page = new PageService(gdao.getCount(pid, sid), "grade-list.action?pid="+pid+"&sid="+sid+"&", pageNow);
			this.request.put("GradeList", gdao.getGradeListByPID(pid,sid, page.getLimit()));
			this.request.put("pageInfo", page.getPageInfo());
			this.request.put("pageList", page.getPageList());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "list-success";
	}
	
	
	public String delete(){
		new GradeDao().deleteGrade(gid);
		return "delete";
	}
	
	/**
	 * 
	 * Description:错题查看
	 * @author: 刘楠
	 * @date: 2017年4月19日
	 * @return String
	 */
	public String showErrorQuestions(){
		GradeDao grade = new GradeDao();
		try {
			String errQids = Tools.decodeBase64(grade.getErrorQids(gid)).replace("(","").replace(")", "");
			System.out.println(errQids);
			this.request.put("Question", new QuestionDao().getErrorQuestions(errQids));
			this.request.put("student", new StudentDao().getOneStudent(sid));
			this.request.put("paperName", Tools.getUTF8Str(pname));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "getErrorQuestions";
	}
	
	
	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	public int getGid() {
		return gid;
	}

	public void setGid(int gid) {
		this.gid = gid;
	}

	public String getPname() {
		return pname;
	}
	public void setPname(String pname) {
		this.pname = pname;
	}
	Map<String, Object> request;
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
	public int getPid() {
		return pid;
	}
	public void setPid(int pid) {
		this.pid = pid;
	}
	public String getPageNow() {
		return pageNow;
	}
	public void setPageNow(String pageNow) {
		this.pageNow = pageNow;
	}
	
	
}
